﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace peonwar
{
    class Menu
    {
        KeyboardState keyboard;
        KeyboardState prevkeyboard;
        GraphicsDevice graphicdevice;
        SpriteBatch spriteBatch = new SpriteBatch(graphicdevice);
        GraphicsDeviceManager graphics;
        MouseState mouse;
        MouseState prevmouse;

        List<string> buttonlist = new List<string>();

        SpriteFont spritefont;

        int selected = 0;




        public Menu()
        {
            
            buttonlist.Add("Play");
            buttonlist.Add("Options");
            buttonlist.Add("Exit");
        
        }

 

        public void LoadContent(ContentManager Content)
        {
            spritefont = Content.Load<SpriteFont>("HudFont");

        }


        public void Update(GameTime gametime)
        {
            keyboard = Keyboard.GetState();
            mouse = Mouse.GetState();


            if (CheckKeyboard(Keys.Up))
            {
                if (selected > 0)
                    selected--;

            }

            if (CheckKeyboard(Keys.Down))
            {
                if (selected < buttonlist.Count - 1)
                    selected++;

            }



            prevkeyboard = keyboard;
            prevmouse = mouse;


        }


        public bool CheckMouse()
        {
            return mouse.LeftButton == ButtonState.Pressed && prevmouse.LeftButton == ButtonState.Released;
        }

        public bool CheckKeyboard(Keys key)
        {
            return (keyboard.IsKeyDown(key) && !prevkeyboard.IsKeyDown(key));
        }

        public void Draw(SpriteBatch spritebatch)
        {
            spriteBatch.Begin();
            Color color;
            for (int i = 0; i < buttonlist.Count; i++)
            {
                if (i == selected)
                    color = Color.Yellow;
                else color = Color.Black;

                spritebatch.DrawString(spritefont, buttonlist[i], new Vector2(300f, (310 / 2 - (spritefont.LineSpacing * buttonlist.Count) / 2) + ((spritefont.LineSpacing + 3) * i)), color);
            }
            spriteBatch.End();

        }




    }
}
